﻿function tabControl(divid) {
    this._divid = divid;
    var _self = this;
    this.init = function () {
        var clic = "javascript:closethis";
        var html = '<ul style="margin-left: 4px;" class="lsfTabControlHeader"></ul> <p class="close" style="font-size:16px;position:absolute;right:-5;top:2">X</p><div style="overflow: auto; max-height: 124px">';
        $("#" + this._divid).append(html);
        $("#" + this._divid + " p.close").click(function () { _self.closethis(); });
    }
    this.init();
    this.closethis = function () {
        $("#" + _self._divid).css("display", "none");
    }
    this.addTabPage = function (relName, title) {
        title = title ? title : relName;
        var html = '<li rel="' + relName + '" class=""><a class="aleft"></a><a class="acenter">' + title + '</a><a class="aright"></a></li>';
        $("#" + this._divid).find("ul").append(html);
        $("#" + this._divid).find("div:first").append("<div rel='" + relName + "'></div>");
        $("#" + this._divid).find("ul li[rel='" + relName + "']").click(function (ele) {
            var oldrel = $("#" + _self._divid + " ul.lsfTabControlHeader li.select").attr("rel");
            var newrel = $(this).attr("rel");
            $("#" + _self._divid + " div[rel='" + oldrel + "']").css("display", "none");
            $("#" + _self._divid + " div[rel='" + newrel + "']").css("display", "block");
            $("#" + _self._divid + " ul li.select").removeClass("select");
            $(this).addClass("select");
        });
        this.selectTabPageByRel(relName);
    }
    this.selectTabPageByIndex = function (index) {
       
    }
    this.selectTabPageByRel = function (relName) {
        if ($("#" + this._divid + " ul.lsfTabControlHeader li.select") != null && $("#" + this._divid + " ul.lsfTabControlHeader li.select").length > 0) {
            var oldrel = $("#" + this._divid + " ul.lsfTabControlHeader li.select").attr("rel");
            $("#" + this._divid + " div[rel='" + oldrel + "']").css("display", "none");
            $("#" + this._divid + " ul.lsfTabControlHeader li.select").removeClass("select");
        }
        $("#" + this._divid + " div[rel='" + relName + "']").css("display", "block");
        $("#" + this._divid + " ul li[rel='" + relName + "']").addClass("select");
    }
    this.removeTabPageByRel = function (relName) {

    }
    this.getTabPage = function (relName) {
        return $("#" + this._divid + " div[rel='" + relName + "']");
    }
    this.removeAllPages = function () {
        $("#" + this._divid + " div div").remove();
        $("#" + this._divid + " ul li").remove();
    }
}